home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
dlx70bbs.zip
/
DLX70SRC.ZIP
/
UTILS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-02-28
|
34KB
|
1,186 lines
{$debug-}
{$line-}
{$include: 'types.int'}
{$include: 'globals.int'}
{$include: 'funs.int'}
{$include: 'database.int'}
{$include: 'load.int'}
{$include: 'loadinit.int'}
{$include: 'utils.int'}
IMPLEMENTATION OF utils;
{DLX Bulletin Board System V7.0
FREEWARE NOTICE
DLX V7.0 is placed in the public domain by its author, Richard Gillmann.
Anyone who wishes to may run the program, copy it, or modify it for
any purpose, including commercial gain.}
USES types,globals,funs,database,load,loadinit;
const
tab = chr(9);
var
screen_ptr [EXTERN] : screen_ads_typ;
wrap0 [EXTERN] : byte;
{***INTERFACE TO THE COM_PAX2 ASYNCHRONOUS COMMUNICATIONS PACKAGE***}
{$include: 'com_pax2.int'}
{***Interface to the PASASM assembler utilities package***}
{$include: 'pasasm.int'}
{$include: 'newasm.int'}
{***Interface to KBD library***}
{$include: 'kbd.int'}
{***Interface to MS Pascal library***}
function getmqq(wants : word) : adsmem; EXTERN;
procedure dismqq(block : adsmem); EXTERN;
function umulok(a,b : word; var c : word) : boolean; EXTERN;
procedure endxqq; EXTERN;
var
doseqq [EXTERN]: word;
procedure konkat{vars d : lstring; consts s : string};
var
i,j : integer;
begin
if ord(d.len)+UPPER(s) > UPPER(d) then
[j:=ord(d.len); d.len:=wrd(UPPER(d));
for i:=j+1 to UPPER(d) do d[i]:=s[i-j]]
else
concat(d,s);
end {konkat};
procedure kopylst{consts s : string; vars d : lstring};
begin
if UPPER(s) > UPPER(d) then
[d.len:=wrd(UPPER(d));
for var i:=1 to UPPER(d) do d[i]:=s[i]]
else
copylst(s,d);
end {kopylst};
procedure kopystr{consts s : string; vars d : string};
begin
if UPPER(s) > UPPER(d) then
for var i:=1 to UPPER(d) do d[i]:=s[i]
else
copystr(s,d);
end {kopystr};
procedure load_em{vars w1,w2 : para};
begin
write('1'); load_ss; load_mn;
fSmall:=true;
write('2'); load_macros;
write('3'); load_script;
fSmall:=false;
w1:=cwn_txt; w2:=wrn_txt;
end {load_em};
function far_alloc{wants : word} {adsmem};
begin
far_alloc:=getmqq(wants);
lhc:=lhc+wants+2;
if lhc>lhc_max then lhc_max:=lhc;
end {far_alloc};
function newpara{consts s : string} {para};
var
w : word;
p : para;
begin
w:=para_size;
if fSmall then
[w:=w-wrd(screen_cols-UPPER(s));
if odd(w) then w:=w+1];
p:=far_alloc(w);
p^.amper:=false; p^.link:=nill; p^.crlfs:=0;
kopylst(s,p^.msg);
newpara:=p;
end {newpara};
procedure dispara{p : adsmem};
var
q : ads of word;
begin
if p.s=0 then return;
q:=p; q.r:=q.r-2;
lhc:=lhc-q^-2;
dismqq(p);
end {dispara};
procedure disparas{vars p : para};
var
q : para;
begin
while p<>nill do
[q:=p; p:=q^.link; dispara(q)];
end {disparas};
procedure newhead{var h : mailhead};
begin
new(h);
h^.head_link:=nil;
h^.text_first:=nill; h^.text_last:=nill;
h^.index:=0; h^.deleted:=false;
end {newhead};
procedure dishead{h : mailhead};
begin
if h<>nil then
[h^.text_first:=nill; h^.text_last:=nill;
h^.index:=0; h^.deleted:=false;
dispose(h)];
end {dishead};
function date2jd{consts dd : string} {integer4};
var
c,ya : integer4;
month,day,year,temp : integer;
w : word;
begin
{get raw date}
month:=(ord(dd[1])-ord('0'))*10 + (ord(dd[2])-ord('0'));
day :=(ord(dd[4])-ord('0'))*10 + (ord(dd[5])-ord('0'));
year :=(ord(dd[7])-ord('0'))*10 + (ord(dd[8])-ord('0'));
{deal with non-American dates}
w := date_format;
if LOBYTE(w)>0 then [temp:=month; month:=day; day:=temp];
if LOBYTE(w)>1 then [temp:=year; year:=day; day:=temp];
{process}
if year>=80
then year:=year+1900
else year:=year+2000;
if month > 2 then
month := month - 3
else begin
month := month + 9; year := year - 1;
end {else};
c := year div 100;
ya := year mod 100;
date2jd := ((146097*c) div 4) + ((1461*ya) div 4) +
((153*month + 2) div 5) + day + 1721119;
end {date2jd};
function time2secs{const tt : string} {integer4};
var
secs : integer4;
begin
if tt[1]>='0' and then tt[1]<='9' then
[secs:=(ord(tt[1])-ord('0'))*10 + (ord(tt[2])-ord('0'));
secs:=secs*60+((ord(tt[4])-ord('0'))*10 + (ord(tt[5])-ord('0')));
secs:=secs*60+((ord(tt[7])-ord('0'))*10 + (ord(tt[8])-ord('0')))]
else
secs:=0;
time2secs:=secs;
end {time2secs};
function copy_of(p : para) : para;
var
p1,p2 : para;
begin
copy_of := nill;
p1:=nill;
while p<>nill do begin
p2:=newpara(p^.msg);
p2^.amper:=p^.amper; p2^.crlfs:=p^.crlfs;
if p1=nill
then copy_of:=p2
else p1^.link:=p2;
p1:=p2;
p:=p^.link;
end {while};
end {copy_of};
procedure replace{vars big_s:lstring; consts little_s:lstring;
pos,xlen : integer};
{big_s is the string to be modified. little_s is the new string
to be inserted into big_s at character position pos, replacing the
next xlen characters to be found there.}
var
little_len,delta,freight,new_len : integer;
begin
if pos<1 or else pos>ord(big_s.len) or else xlen<0 then return;
if xlen+pos-1 > ord(big_s.len) then xlen := ord(big_s.len)-pos+1;
little_len:=ord(little_s.len);
delta:=little_len-xlen;
if delta<>0 then begin
freight:=ord(big_s.len)-pos-xlen+1;
new_len:=ord(big_s.len)+delta;
if new_len>UPPER(big_s) then
[freight:=freight-(new_len-UPPER(big_s));
new_len:=UPPER(big_s)];
if delta>0 then big_s.len:=wrd(new_len);
if freight>0 then
[if delta>0 then {shift right}
movesr(ads big_s[pos+xlen],ads big_s[pos+little_len],wrd(freight))
else {shift left}
movesl(ads big_s[pos+xlen],ads big_s[pos+little_len],wrd(freight))];
if delta<0 then big_s.len:=wrd(new_len);
end {if};
if pos+little_len>UPPER(big_s) then
little_len:=UPPER(big_s)-pos+1;
if little_len>0 then
[if pos+little_len-1>ord(big_s.len) then big_s.len:=wrd(pos+little_len-1);
movesl(ads little_s[1],ads big_s[pos],wrd(little_len))];
end {replace};
{evaluate if condition}
{truth value of s[i1..i2-1] op s[i2..i3]}
function tvalue(consts s : lstring; i1,i2,i3 : integer; op : char) : boolean;
var
s0,s1,s2 : lstring(screen_cols div 2);
j,k : integer;
j4,k4 : integer4;
begin
if i1=0 or else i3=0 then [tvalue:=false; return];
if i2=0 then {no operator}
[tvalue := (scanne(i3-i1+1,' ',s,i1) < i3-i1+1);
return];
s0.len := wrd(i2-i1+1);
if s0.len > UPPER(s0) then s0.len:=UPPER(s0);
if s0.len > 0 then movesl(ads s[i1],ads s0[1],s0.len);
stripx(s0,s1);
s0.len := wrd(i3-i2+1);
if s0.len > UPPER(s0) then s0.len:=UPPER(s0);
if s0.len > 0 then movesl(ads s[i2],ads s0[1],s0.len);
stripx(s0,s2);
if op=':' then
[for j:=1 to ord(s1.len) do s1[j]:=uc(s1[j]);
for j:=1 to ord(s2.len) do s2[j]:=uc(s2[j]);
tvalue := (positn(s2,s1,1) > 0)]
else if decode(s1,j4) and then decode(s2,k4) then
case op of
'<' : tvalue := (j4 < k4);
'=' : tvalue := (j4 = k4);
'#' : tvalue := (j4 <> k4);
'>' : tvalue := (j4 > k4);
otherwise tvalue:=false;
end {case}
else begin
if s1.len < s2.len then k:=ord(s1.len) else k:=ord(s2.len);
for j:=1 to k do
if uc(s1[j]) < uc(s2[j]) then
[tvalue := (op = '<'); return]
else if uc(s1[j]) > uc(s2[j]) then
[tvalue := (op = '>'); return];
case op of
'<' : tvalue := (s1.len < s2.len);
'=' : tvalue := (s1.len = s2.len);
'>' : tvalue := (s1.len > s2.len);
end {case};
end {else};
end {tvalue};
{expand ampersand codes}
function substitute{vars s : lstring} {boolean};
var
i,j : integer;
str : lstring(screen_cols);
delta : integer;
c1,c2 : char;
if1,if2 : integer;
ifop : char;
skipmode : boolean;
begin
substitute:=true;
if1:=0; if2:=0; ifop:=' '; skipmode:=false;
i:=1;
while i<=ord(s.len)-2 do begin
i:=i+scaneq(ord(s.len),'&',s,i);
if i>ord(s.len)-2 then break;
c1:=s[i+1]; c2:=uc(s[i+2]);
if c1='-' and then c2='-' then {comment}
[s.len:=wrd(i-1); br